//
//  CZBaseViewController.swift
//  git
//
//  Created by 徐 鹏超 on 16/4/9.
//  Copyright © 2016年 徐 鹏飞. All rights reserved.
//

import UIKit
/*
抽取步骤
1.把原来代码复制过来
2.原来的代理尽量 注释掉
3.注释掉代码之后,对程序没有影响的情况下,把原来的抽取代码可以删除掉
*/
class CZBaseViewController: UITableViewController,CZVisitorViewDelegate {
    let visitor = CZVisitorView()
    
    let isBaseLogin: Bool = CZUserModel.getModel()?.access_token == nil ? false: true
    
    override func loadView() {
        //
        print("loadView")
        
        if isBaseLogin{
            super.loadView()
        }else{
        // 设置代理对象,一定要遵守协议
        visitor.delegate = self
        
        view = visitor
        
        // 修改 导航
        setupNav()
        }
    }
    
    private func setupNav(){
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "didRegisterMethod")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "didLoginMethod")
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    //MARK:-- CZVisitorViewDelegate代理方法
    func didRegisterMethod() {
        
        printLog("输出日志")
        print("代理实现注册")
        
        let oauth = CZOauthViewController()
        
        let nav = UINavigationController(rootViewController: oauth)
        //跳转
        presentViewController(nav, animated: true) { () -> Void in
             
        }
        
    }
    
    func didLoginMethod() {
        print("代理实现登录")
    }

}
